home *** CD-ROM | disk | FTP | other *** search
- Path: ratty.wolfe.net!neus
- From: neus@wolfenet.com (Bill Campbell)
- Newsgroups: comp.lang.c
- Subject: why is this an infinite loop?
- Date: 19 Jan 1996 23:33:57 GMT
- Organization: Wolfe Internet Access, L.L.C.
- Message-ID: <4dp9p5$jm2@news1.wolfe.net>
- NNTP-Posting-Host: sea-ts1-p07.wolfenet.com
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- Beginning c student can't figure out why this small function to read in a
- value for the variable x causes an infinite loop when it receives unexpected
- input.
-
- double get_x()
- {
- int test;
- double x;
-
- printf("Enter a numeric value for x: ");
-
- while(scanf("%lf", &x) != 1)
- {
- printf("ERROR - program expecting a number");
- printf("Enter a numeric value for x: ");
- }
-
- return x;
- }
-